package com.ruoyi.web.controller.module.event;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.common.utils.PageUtils;
import com.ruoyi.system.domain.module.event.EventPatrolLineInfo;
import com.ruoyi.system.service.module.event.IEventPatrolLineInfoService;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 巡更线路的点集合Controller
 *
 * @author ruoyi
 * @date 2023-12-26
 */
@Validated
@Api(value = "巡更线路的点集合控制器", tags = {"巡更线路的点集合管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/module/event/patrol/line/info")
public class EventPatrolLineInfoController extends BaseController {

    private final IEventPatrolLineInfoService eventPatrolPointInfoService;

    /**
     * 查询巡更线路的点集合列表
     */
    @ApiOperation("查询巡更线路的点集合列表")
    @PreAuthorize("@ss.hasPermi('module:patrolPointInfo:list')")
    @GetMapping("/list")
    public TableDataInfo<EventPatrolLineInfo> list(@Validated EventPatrolLineInfo eventPatrolLineInfo) {
        QueryWrapper<EventPatrolLineInfo> qw = new QueryWrapper<>();
		if(eventPatrolLineInfo.getLineId()!= null){
			qw.eq("line_id", eventPatrolLineInfo.getLineId());
		}

        TableDataInfo<EventPatrolLineInfo> td = PageUtils.buildDataInfo(eventPatrolPointInfoService.page(PageUtils.buildPage(),qw));
        List<EventPatrolLineInfo> list = td.getRows();
        return td;
    }

    /**
     * 导出巡更线路的点集合列表
     */
    @ApiOperation("导出巡更线路的点集合列表")
    @PreAuthorize("@ss.hasPermi('module:patrolPointInfo:export')")
    @Log(title = "巡更线路的点集合", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<EventPatrolLineInfo> export(@Validated EventPatrolLineInfo eventPatrolLineInfo) {
        List<EventPatrolLineInfo> list = eventPatrolPointInfoService.list();
        ExcelUtil<EventPatrolLineInfo> util = new ExcelUtil<EventPatrolLineInfo>(EventPatrolLineInfo.class);
        return util.exportExcel(list, "巡更线路的点集合");
    }

    /**
     * 获取巡更线路的点集合详细信息
     */
    @ApiOperation("获取巡更线路的点集合详细信息")
    @PreAuthorize("@ss.hasPermi('module:patrolPointInfo:query')")
    @GetMapping("/{id}")
    public AjaxResult<EventPatrolLineInfo> getInfo(@NotNull(message = "主键不能为空") @PathVariable("id") Integer id) {
        EventPatrolLineInfo eventPatrolLineInfo = eventPatrolPointInfoService.getById(id);
        return AjaxResult.success(eventPatrolLineInfo);
    }

    /**
     * 新增巡更线路的点集合
     */
    @ApiOperation("新增巡更线路的点集合")
    @PreAuthorize("@ss.hasPermi('module:patrolPointInfo:add')")
    @Log(title = "巡更线路的点集合", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated(AddGroup.class) @RequestBody EventPatrolLineInfo eventPatrolLineInfo) {
        return toAjax(eventPatrolPointInfoService.save(eventPatrolLineInfo) ? 1 : 0);
    }

    /**
     * 修改巡更线路的点集合
     */
    @ApiOperation("修改巡更线路的点集合")
    @PreAuthorize("@ss.hasPermi('module:patrolPointInfo:edit')")
    @Log(title = "巡更线路的点集合", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated(EditGroup.class) @RequestBody EventPatrolLineInfo eventPatrolLineInfo) {
        return toAjax(eventPatrolPointInfoService.updateById(eventPatrolLineInfo) ? 1 : 0);
    }

    /**
     * 删除巡更线路的点集合
     */
    @ApiOperation("删除巡更线路的点集合")
    @PreAuthorize("@ss.hasPermi('module:patrolPointInfo:remove')")
    @Log(title = "巡更线路的点集合" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")  @PathVariable Integer[] ids) {
        return toAjax(eventPatrolPointInfoService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
